package org.itboys.core.service.mongo.front;

import org.itboys.commons.ErrorException;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.core.common.SundayCommonConstants;
import org.itboys.core.entity.mongo.SundayContactMessage;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.itboys.param.ParamUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/21
 * Description:联系客服小程序服务类
 */

@Service
public class SundayFrontContactMessageService extends BaseMongoService<SundayContactMessage> {
    @Resource(name = "mobileDs")
    private MongoDataSource mongoDataSource;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return mongoDataSource;
    }

    @Override
    protected Class<SundayContactMessage> getEntityClass() {
        return SundayContactMessage.class;
    }

    /**
     * 用户提交联系客服内容
     * @param memberId
     * @param memberName
     * @param name
     * @param text
     */
    public void save(Long memberId, String memberName, String name, String text){
        SundayContactMessage message = new SundayContactMessage(memberId, memberName, name, text);
        message.setStatus(1);
        super.save(message);
    }

    /**
     * 查询用户所有回馈消息
     * @param request
     * @param memberId
     */
    public List<SundayContactMessage> select(HttpServletRequest request, Long memberId){
        Map<String, Object> param = ParamUtil.packageMongoExactParam(request);
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("memberId", memberId);
        param.put("status", SundayCommonConstants.NO);

        List<SundayContactMessage> list = super.pageQuery(request, param).getData();

        if (ListUtil.isNotNull(list)){
            return list;
        }else {
            throw new ErrorException("暂无消息");
        }

    }

}
